package cn.net.csit.platform_cloud.utils;

import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

/**
 * @title: MapAndStringUtil
 * @Description: String和Map之间的转换 主要用于扩展字段处理
 * @Author yanbingtai
 * @Date 2019/4/25 17:32
 */
public class MapAndStringUtil {

    public static Map<String,String>  stringToMap(String string){
        Gson gson  = new Gson();
        Map<String,String> params = new HashMap<>();
        params =gson.fromJson(string,params.getClass());
        return params;
    }

    public static Map<String,Object>  stringToMapObjet(String string){
        Gson gson  = new Gson();
        Map<String,Object> params = new HashMap<>();
        params =gson.fromJson(string,params.getClass());
        return params;
    }

    public static String mapToString(Map<String,String> map){
        String string = JSONObject.toJSONString(map);
        return string;
    }
}
